<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>点餐统计-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"> <a onclick="back()" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title">点餐统计</h1>
	    </div>
		<div class="weui_tab_bd">
			<div class="weui_cells weui_cells_access mt0">
               <div class="weui_cell">
               	   <div class="weui_cell_bd mr20">选择日期</div>
                   <div class="weui_cell_bd weui_cell_primary">
                     <input class="weui_input" type="text" id="orderDate"/>
                   </div>
                   <div class="weui_cell_bd" onclick="totalDateOrder()" style="text-align: right; padding: 2px 10px;background: #efefef; border-radius: 5px; color: #18b4ed;">
                   		查询
                   </div>
               </div>   
           </div>
           <div class="weui_cells_title pt15 pb15 f16"><span id="dateName"></span>点餐名单</div>
           <div class="weui_cells">
	           <div class="page-bd xs_c_search">
					<ul>
						<li class="xs_c_search-first">
			                <div class="weui-flex js-category">
			                    <p class="weui-flex-item">早餐<span class="pl20" id="lunchCount"></span></p>
			                    <i class="icon icon-74"></i>
			                </div>
			                <div class="page-category js-categoryInner">
			                    <ul class="list_5" id="lunchList">
			                    </ul>
			                </div>
			            </li>
			            <li class="">
			                <div class="weui-flex js-category">
			                    <p class="weui-flex-item">晚餐<span class="pl20" id="dinnerCount"></span></p>
			                    <i class="icon icon-74"></i>
			                </div>
			                <div class="page-category js-categoryInner">
			                    <ul class="list_5" id="dinnerList">
			                    </ul>
			                </div>
			            </li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<script src="<%=basePath %>/js/picker.js"></script>
	<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		var today = getTime(new Date(),'yyyy-MM-dd');
		$("#orderDate").val(today);
		$("#orderDate").datetimePicker({
			title : "选择日期",
			m : 1
		});
		$('.js-category').click(function() {
			$parent = $(this).parent('li');
			if ($parent.hasClass('js-show')) {
				$parent.removeClass('js-show');
				$(this).children('i').removeClass('icon-35')
						.addClass('icon-74');
			} else {
				$parent.siblings().removeClass('js-show');
				$parent.addClass('js-show');
				$(this).children('i').removeClass('icon-74')
						.addClass('icon-35');
				$parent.siblings().find('i').removeClass('icon-35')
						.addClass('icon-74');
			}
		});
		totalDateOrder();
	})
	function totalDateOrder() {
		var date = $("#orderDate").val();
		$("#dateName").html(getMyDay(new Date(date))+"("+date+")");
		$.ajax({
	   		url: basePath + "/ls/order/food/totalDateOrder",
	   		type: 'POST',
	   		dataType : "json",
	   		data: {
	   			orderDate: date
	   		},
	   		success: function(data) {
	   			var lunch = 0,dinner = 0;
	   			if(data != null && data.length > 0) {
	   				for(var i in data) {
	   					if(data[i].orderType == '午餐') lunch = data[i].total;
	   					else if(data[i].orderType == '晚餐') dinner = data[i].total;
	   				}
	   			}
	   			$("#lunchCount").html("人数："+lunch);
	   			$("#dinnerCount").html("人数："+dinner);
	   			seacherList();
 	   		},
	   		error: function(data) {
	   		}
		});
	}
	function seacherList() {
		$.ajax({
			type: "post",
			url: basePath + "/ls/order/food/queryOrderList",
			data: {
				orderDate: $("#orderDate").val()
			},
			dataType:"json",
			success:function(data){
				var lunchHtml="", dinnerHtml="";
				if(data != null && data.total > 0) {
            		for(var i in data.rows) {
            			var itm = data.rows[i];
            			var str = "<li>" + itm.teacherName + "</li>";
            			if(itm.orderType == '午餐') {
            				lunchHtml += str;
            			} else if(itm.orderType == '晚餐') {
            				dinnerHtml += str;
            			}
            		}
            	}
				$("#lunchList").html(lunchHtml);
            	$("#dinnerList").html(dinnerHtml);
			}
		});
	}
	function getMyDay(date){
		var week;
		if(date.getDay()==0) week="周日"
		if(date.getDay()==1) week="周一"
		if(date.getDay()==2) week="周二"
		if(date.getDay()==3) week="周三"
		if(date.getDay()==4) week="周四"
		if(date.getDay()==5) week="周五"
		if(date.getDay()==6) week="周六"
		return week;
	}
</script>
</body>
</html>